#include<iostream>
#include<vector>

using namespace std;
int threeSumClosest(vector<int>& nums, int target) {
    int len = nums.size();
    int tmp = 0;
    int res;
    int minDiff = 0;
    int diff = abs(nums[0] + nums[1] + nums[2] - target);
    for (int i = 0; i < len - 2; i++) {
        for (int j = i + 1; j < len - 1; j++) {
            for (int k = j + 1; k < len; k++) {
                tmp = nums[i] + nums[j] + nums[k];
                if (abs(target - tmp) <= diff) {
                    diff = abs(target - tmp); // don't forget
                    res = tmp;
                }
            }
        }
    }
    return res;
}
int main(){
    vector<int> nums = {1,1, -1, -1, 3};
    int target = -1;
    int res = threeSumClosest(nums, target);
    cout << res << endl;
}